<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>login</title>
</head>
<script src="https://cdn.staticfile.org/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript">

    $(document).ready(function () {
        welcome()
    });
    function welcome(){
        var token = $.cookie("token");
        if(token != undefined && token != ""){
            $.ajax("http://www.godme.com/api/user/check/"+token,
                {
                    type: "post",
                    success: function (data, status) {
                        if(data != ""){
                            sessionStorage.setItem("user", data);
                            window.location.href = "welcome.html";
                        }
                    }
                }
            )
        }
    }
    function register(){
        window.location.href = "/static/register.html"
    }
    function login() {
        var url = "http://www.godme.com/api/user/login/"+$("#mail").val()+"/"+$("#password").val();
        $.ajax(url,
            {
                type: 'post',
                success: function(data, status) {
                    console.log(data);
                    if(data){
                        welcome();
                    }else{
                        confirm("用户名或密码错误");
                    }

                },
            })
    }


</script>
<body style="margin-left: 45%; margin-top: 10%">
        <table>
            <caption>welcome</caption>
            <tr>
                <td><input type="email" id="mail" placeholder="email"></td>
            </tr>
            <tr>
                <td><input type="password" id="password" placeholder="password"></td>
            </tr>
            <tr>
                <td><input type="button" value="register" style="float: left" onclick="register()"> <input type="button" onclick="login()" value="login" style="float: right"></td>
            </tr>

        </table>
</body>
</html>